package com.hzw.video.opengl

import android.opengl.GLES20
import android.opengl.GLSurfaceView
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

/**
 *
 * @Author:         HuaZhongWei
 * @CreateDate:     2020/9/23 14:33
 *
 * @Description:
 *
 */
class SimpleRender(val drawer: IDrawer) : GLSurfaceView.Renderer {
    override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
        GLES20.glClearColor(0f, 0f, 0f, 0f)
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
//        drawer.setTextureID(createTextureIds(1)[0])
        drawer.setTextureID(0)
    }

    override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
        GLES20.glViewport(0, 0, width, height)
    }

    override fun onDrawFrame(gl: GL10?) {
        drawer.draw()
    }

    fun createTextureIds(count: Int): IntArray = IntArray(count).also {
        GLES20.glGenTextures(count, it, 0)
    }
}